package com.example.wallpaperapp.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * @Package: com.example.wallpaperapp.utils
 * @ClassName: IntentUtil
 * @Description: intent工具类
 * @Author: zrmo
 * @CreateDate: 2020/10/30 19:37
 */

public class IntentUtil {
    //普通跳转
    public static void startActivity(Class<?> clz, Context context) {
        startActivity(clz, null, context);
    }
    //携带数据的页面跳转
    public static void startActivity(Class<?> clz, Bundle bundle, Context context) {
        Intent intent = new Intent();
        intent.setClass(context, clz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }
    //A返回信息跳转B
    public static void startActivityForResult(Class<?> clz, int code, Activity context) {
        Intent intent = new Intent();
        intent.setClass(context, clz);
        context.startActivityForResult(intent, code);
    }

    //B回调信息
    public static void returnDatas(int code, String key, String data, Activity context) {
        Intent datas = new Intent();
        datas.putExtra(key, data);
        context.setResult(code, datas);
        context.finish();
    }
}

